<template>
  <div>
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/homepage' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>全部商品</el-breadcrumb-item>
      <el-breadcrumb-item>分类</el-breadcrumb-item>
      <el-breadcrumb-item></el-breadcrumb-item>
    </el-breadcrumb>
    <div class="List-top">
      <div class="title">分类</div>
      <el-tabs
        v-model="activeName"
        type="card"
        style="width: 1500px;line-height: 30px;font-size: 16px; margin-left: 96px;"
      >
        <el-tab-pane v-for="item in BiaoList" :key="item.category_id" :label="item.category_name"></el-tab-pane>
      </el-tabs>
    </div>
    <my-list :listData="Product" :ismore="true"></my-list>
    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :total="total"
        @current-change="currentChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import API from "../api/shopp";
export default {
  data() {
    return {
      activeName: "0",
      BiaoList: [],
      Product: [],
      allProduct: [],
      categoryID: [],
      currentPage: 1,
      pageSize: 15,
      total: 0
    };
  },
  activated() {
    this.activeName = "-1";
  },
  created() {
    this.List();
    this.AllProduct("AllShoppList");
    // this.getProduct();
  },
  watch: {
    activeName(value) {
      this.categoryID = [value * 1];
      if (value === "0") {
        this.categoryID = [];
         this.categoryID = [categoryID];
          this.currentPage = 1;
        this.AllProduct("AllShoppList");
      } else {
        this.AllProduct();
      }
    },
    currentPage(currentPage) {
      if (!this.categoryID.length) {
        this.getProduct("AllShoppList");
        return;
      }
      this.Product();
    }
  },
  methods: {
    // 分类标题
    async List() {
      let res = await API.shoppList();
      this.BiaoList = res.category;
      this.BiaoList.unshift({
        category_id: 0,
        category_name: "全部"
      });
    },
    currentChange(currentPage) {
      this.currentPage = currentPage;
    },
    //全部数据
    async AllProduct(apiName = "ListShopp") {
      let sendData = {
        categoryID: this.categoryID,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      };
      let res = await API[apiName](sendData);
      this.Product = res.Product;
      this.total = res.total;
      console.log(this.total);
      console.log(this.allProduct);
    }
  }
};
</script>
<style lang="scss" scoped>
.el-breadcrumb {
  width: 1500px;
  line-height: 30px;
  font-size: 16px;
  margin-left: 96px;
}
.title {
  font-size: 20px;
  font-weight: 500;
  color: #303133;
  position: relative;
  top: 10px;
  left: 92px;
}
.List-top {
  display: flex;
}
</style>
